function twoSum(nums, target) {
  const map = new Map()
  for (let i = 0, l = nums.length; i < l; i++) {
    if (map.has(target - nums[i])) {
      return [map.get(target - nums[i]), i]
    } else {
      map.set(nums[i], i)
    }
  }
  return []
}

console.log(twoSum([3, 2, 4], 6))